package com.example.iteratorpattern.entity;

/**
 * @author ash
 * @description
 * @create 2023/2/20  23:26:19
 * @className ConcreteIterator
 * @verson 1.0.0
 */
public class ConcreteIterator extends Iterator{

    private ConcreteAggregate aggregate;
    private int current = 0;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public Object first() {
        return aggregate.get(0);
    }

    @Override
    public Object next() {
        Object ret = null;
        current++;
        if (current < aggregate.count()){
            ret =aggregate.get(0);
        }
        return ret;
    }

    @Override
    public boolean isDone() {
        return current >= aggregate.count();
    }

    @Override
    public Object currentItem() {
        return aggregate.get(current);
    }
}
